package main

import (
	"fmt"
)

func main() {
	fmt.Println("Hello")
	ifDemo()
	switchDemo(87)
	switchDemo_01("wechat")
	result := switchDemo_02("*", 3, 5)
	fmt.Println(result)
	switchDemo_03()
	switchDemo_04()
}

/**
 * if示例
 */
func ifDemo() {
	var a int = 100

	if a < 20 {
		println(a)
	} else {
		println("数值必须小于20")
	}

	//if高级写法
	if b := 20; b > 18 {
		fmt.Println("已是成年人了")
	}
}

/**
 *  switch demo
 */
func switchDemo(marks uint8) {
	/* 定义局部变量 */
	var grade string = "B"
	//var marks int = 90
	flag := true

	switch flag {
	case marks >= 90:
		grade = "A"
	case marks >= 80:
		grade = "B"
	case marks > 70:
		grade = "C"
	default:
		grade = "D"
	}

	switch {
	case grade == "A":
		fmt.Printf("优秀!\n")
	case grade == "B", grade == "C":
		fmt.Printf("良好\n")
	case grade == "D":
		fmt.Printf("及格\n")
	case grade == "F":
		fmt.Printf("不及格\n")
	default:
		fmt.Printf("差\n")
	}
	fmt.Printf("你的等级是 %s\n", grade)
}

func switchDemo_01(payType string) {

	switch payType {
	case "alipay":
		fmt.Println("支付宝支付")
	case "wechat":
		fmt.Println("微信支付")
	case "union":
		fmt.Println("银联支付")
	}
}

/**
 * switch+多参数函数
 */
func switchDemo_02(operator string, a, b int16) int16 {
	switch operator {
	case "+":
		return a + b
	case "/":
		return a / b
	case "*":
		return a * b
	case "-":
		return a - b
	case "%":
		return a % b
	default:
		return a + b
	}
}

/**
 * case 多条件
 */
func switchDemo_03() {
	month := 2
	switch month {
	case 12, 1, 2:
		fmt.Println("冬天")
	case 3, 4, 5:
		fmt.Println("春天")
	case 6, 7, 8:
		fmt.Println("夏天")
	case 9, 10, 11:
		fmt.Println("秋天")
	default:
		fmt.Println("输入有误")
	}
}

func switchDemo_04() {
	switch i := 2; i * 4 {
	case 8:
		j := 0
		fmt.Println(i, j)
	default:
		fmt.Println("default")
	}
}
